//
//  NSOBject+runtime.m
//  ITsmartHome
//
//  Created by JM on 15/8/11.
//
//

#import "NSOBject+runtime.h"

@implementation NSObject (runtime)

- (NSDictionary *)propertiesDic {
    NSMutableDictionary *props = [NSMutableDictionary dictionary];
    unsigned int outCount, i;
    objc_property_t * properties = class_copyPropertyList([self class], &outCount);
    
    for (i = 0; i < outCount; i++) {
        objc_property_t property = properties[i];
        NSString *propertyName = [[NSString alloc] initWithCString:property_getName(property) encoding:NSUTF8StringEncoding];
        id propertyValue = [self valueForKey:(NSString *)propertyName];
        if (!propertyValue){
            propertyValue = @"nil";
        }
            
        [props setObject:propertyValue forKey:propertyName];
    }
    free(properties);
    return props;
}
@end
